package com.saic.localfileloader.main;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLException;

public class Test {

	public static void main(String[] args) throws SQLException, IOException {

		if (args.length < 1) {
			System.out.println("Less params");
			return;
		}

		String path = args[0];
		DBUtil db = new DBUtil();
		BufferedReader br = new BufferedReader(new InputStreamReader(
				new FileInputStream(path)));
		String line = null;
		int cnt = 0;
		String sql = "";
		while (null != (line = br.readLine())) {
			String[] tmp = line.split("\\s+");
			if (cnt == 0) {
				sql = "insert into testin\n";
			}
			sql += "select " + tmp[0] + "," + tmp[1] + "," + tmp[2] + ","
					+ tmp[3] + " from dual union all\n";
			cnt++;
			if (cnt % 100 == 0) {
				cnt %= 100;
				db.insert(sql.substring(0,
						sql.length() - "union all\\n".length()));
				sql = "";
			}
		}
		if (sql.length() > 0) {
			db.insert(sql.substring(0, sql.length() - "union all\\n".length()));
		}
		br.close();
		db.close();
	}

}
